using System;
using UnityEngine;

namespace Scene.Scripts
{
    public class SceneLaunch : MonoBehaviour
    {
        [SerializeField]
        private Transform mainRoleTrans;
        [SerializeField]
        private LoadRadius[] loadRadius;
        [SerializeField]
        private SceneLoadConfig config;

        private bool _loadingFinish = false;
        private System.Collections.IEnumerator Start()
        {
            string[] scenes = new string[]
            {
                "Assets/TestScene/AutoGen/New Scene 1.unity",
                "Assets/TestScene/AutoGen/New Scene 2.unity",
                "Assets/TestScene/AutoGen/New Scene 3.unity",
                "Assets/TestScene/AutoGen/New Scene 4.unity",
                "Assets/TestScene/AutoGen/New Scene 5.unity",
                "Assets/TestScene/AutoGen/New Scene 6.unity",
                "Assets/TestScene/AutoGen/New Scene 7.unity",
                "Assets/TestScene/AutoGen/New Scene 8.unity",
            };

            string glo = "Assets/TestScene/AutoGen/_GLOBAL.unity";
            _loadingFinish = false;
            yield return SceneBox.LoadScene(config, mainRoleTrans.position, loadRadius);
            _loadingFinish = true;
        }

        private void LateUpdate()
        {
            /*
             * 每帧刷新角色当前的位置以及资源加载半径
             * 获取整个空间中需要加载的truck
             * 根据每个truck被包含的次数给出加载优先级
             * 
            */
            if (_loadingFinish)
            {
                SceneBox.UpdateScene(mainRoleTrans.position, loadRadius);
            }
        }

        private void OnDestroy()
        {
            SceneBox.OnSceneQuit();
        }
    }

}